define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'student/index' + location.search,
                    add_url: 'student/add',
                    edit_url: 'student/edit',
                    del_url: 'student/del',
                    multi_url: 'student/multi',
                    import_url: 'student/import',
                    table: 'student',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'stu_number', title: __('Stu_number'), operate: 'LIKE'},
                        {field: 'exam_number', title: __('Exam_number'), operate: 'LIKE'},
                        {field: 'entry_year', title: __('Entry_year'), operate: 'LIKE'},
                        {field: 'grade_data', title: __('Grade_data'), searchList: {"1":__('Grade_data 1'),"2":__('Grade_data 2'),"3":__('Grade_data 3'),"4":__('Grade_data 4')}, formatter: Table.api.formatter.normal},
                        {field: 'grade.name', title: __('Grade.name'), operate: 'LIKE'},
                        {field: 'gclass.name', title: __('Gclass.name'), operate: 'LIKE'},
                        {field: 'school.name', title: __('School.name'), operate: 'LIKE'},
                        {field: 'tag', title: __('Tag'), searchList: {"1":__('Tag 1'),"2":__('Tag 2'),"3":__('Tag 3'),"4":__('Tag 4'),"5":__('Tag 5')}, formatter: Table.api.formatter.flag},
                        {field: 'subject_ids', title: __('Subject_ids'), operate: false,formatter: Table.api.formatter.label},
                        {field: 'foreign_subject_ids', title: __('Foreign_subject_ids'), operate: false,formatter: Table.api.formatter.label},
                        {field: 'chinese_class', title: __('Chinese_class'), operate: 'LIKE'},
                        {field: 'maths_class', title: __('Maths_class'), operate: 'LIKE'},
                        {field: 'english_class', title: __('English_class'), operate: 'LIKE'},
                        {field: 'physics_class', title: __('Physics_class'), operate: 'LIKE'},
                        {field: 'chemistry_class', title: __('Chemistry_class'), operate: 'LIKE'},
                        {field: 'organism_class', title: __('Organism_class'), operate: 'LIKE'},
                        {field: 'politics_class', title: __('Politics_class'), operate: 'LIKE'},
                        {field: 'history_class', title: __('History_class'), operate: 'LIKE'},
                        {field: 'geography_class', title: __('Geography_class'), operate: 'LIKE'},
                        {field: 'other_class', title: __('Other_class'), operate: 'LIKE'},
                        {field: 'parent_name', title: __('Parent_name'), operate: 'LIKE'},
                        {field: 'parent_phone', title: __('Parent_phone'), operate: 'LIKE'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $("#c-grade_id").data("params", function (obj) {
                return {custom: {school_id: $("#c-school_id").val()}};
            });
            $("#c-class_id").data("params", function (obj) {
                return {custom: {grade_id: $("#c-grade_id").val()}};
            });
            $("#c-subject_ids").data("params", function (obj) {
                return {custom: {type: 1}};
            });
            $("#c-foreign_subject_ids").data("params", function (obj) {
                return {custom: {type: 2}};
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-grade_id").data("params", function (obj) {
                return {custom: {school_id: $("#c-school_id").val()}};
            });
            $("#c-class_id").data("params", function (obj) {
                return {custom: {grade_id: $("#c-grade_id").val()}};
            });
            $("#c-subject_ids").data("params", function (obj) {
                return {custom: {type: 1}};
            });
            $("#c-foreign_subject_ids").data("params", function (obj) {
                return {custom: {type: 2}};
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
